/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.admin;

import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import javax.ejb.EJB;
import model.*;
import java.util.*;
import entities.*;

/**
 *
 * @author xuanthuy
 */
@Named(value = "fAQsManagedBean")
@SessionScoped
public class FAQsManagedBean implements Serializable {

    @EJB
    private FAQsFacade fAQsFacade;
    private FAQs faq = new FAQs();

    private String message = "";

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public FAQs getFaq() {
        return faq;
    }

    public void setFaq(FAQs faq) {
        this.faq = faq;
    }

    public FAQsManagedBean() {
    }

    // bat dau
    public List<FAQs> findAll() {
        return this.fAQsFacade.sudungtruyvan();
    }

    //them
    public String add() {
        return "FAQsAdAdd?faces-redirect=true";
    }

    public String addFAQ() {
        FAQs temp = this.fAQsFacade.checkName(faq.getQuestion());
        if (temp == null) {
            this.faq.setStatus(Boolean.TRUE);
            this.fAQsFacade.create(this.faq);
            return "FAQsAd?faces-redirect=true";
        } else {
            this.message = faq.getQuestion() + " already exists! Please choose Question different!";
            return "";
        }
    }

    //clear
    public void clear() {
        this.faq.setQuestion("");
        this.faq.setAnswer("");
    }

    // edit
    public String edit(FAQs faq) {
        this.faq = faq;
        return "FAQsAdEdit";
    }

    public String xulycapnhat() {
        this.fAQsFacade.edit(this.faq);
        return "FAQsAd?faces-redirect=true";
    }

    // xoa An
    public void xoaAn(FAQs faq) {
        this.faq = faq;
        this.faq.setStatus(Boolean.FALSE);
        this.fAQsFacade.edit(this.faq);
    }

    //phuc hoi
    public String recoverDatadelete() {
        return "FAQsAdRecover";
    }

    public List<FAQs> sudungtruyvan1() {
        return this.fAQsFacade.truyvan1();
    }

    public String recoverData(FAQs faq) {
        this.faq = faq;
        this.faq.setStatus(Boolean.TRUE);
        this.fAQsFacade.edit(this.faq);
        return "FAQsAd?faces-redirect=true";
    }

    // xoa luon
    public void xoa(FAQs faq) {
        this.fAQsFacade.remove(faq);
    }
}
